use crate::address::{IPC, MY};
use cfw_kit::{Logger, Write2};
use proto_bytes::{frame::Proto, package::ty};

pub mod cmd_can;

#[cfg(any(feature = "cp_drop", feature = "boot_drop"))]
pub mod cmd_uart;

struct LogW;

impl Write2 for LogW {
    fn write(buf: &[u8]) {

        #[cfg(feature = "use_can_log")]
        cmd_can::write(Proto {
            ty: ty::LOG,
            seq: 0,
            src: MY,
            dst: IPC,
            body: buf,
        });

        #[cfg(feature = "use_uart_log")]
        cmd_uart::write(Proto {
            ty: ty::LOG,
            seq: 0,
            src: MY,
            dst: IPC,
            body: buf,
        });
    }
}

static LOGGER: Logger<LogW, 200> = Logger::uninit();

pub unsafe fn init() {
    cmd_can::init();
    #[cfg(feature = "use_uart_log")]
    cmd_uart::init();

    LOGGER.init_once();
}
